/**
 * 
 */
package org.kknd.thetvdblib;

import java.util.List;

import org.kknd.thetvdblib.pojo.Language;
import org.kknd.thetvdblib.pojo.Mirror;

/**
 * @author Christian
 * 
 */
public class TheTVDB {
    /** Error message when getting an instance with no api key. */
    private static final String ERR_NO_INSTANCE = "No API key set, try to get an instance with an API key!";
    /** The API key to use the TVDB API. */
    private final String apiKey;
    /** Singleton for API access. */
    private static TheTVDB instance;

    /**
     * Creates an instance for accessing theTVDB API.
     * 
     * @param apiKey the API key for auth
     */
    private TheTVDB(String apiKey) {
        this.apiKey = apiKey;
    }

    /**
     * Gets the current instance of theTVDB API handler.
     * 
     * @return an instance of {@link TheTVDB}
     * @throws IllegalStateException when trying to get an instance which does
     *             not exist and no API key is set.
     */
    public static TheTVDB getInstance() throws IllegalStateException {
        TheTVDB result = null;
        if (instance != null) {
            result = instance;
        } else {
            throw new IllegalStateException(ERR_NO_INSTANCE);
        }

        return result;
    }

    /**
     * Gets the current instance of theTVDB API handler, or creates a new one
     * with the given API key.
     * 
     * @param apiKey the API key for auth
     * @return an instance of {@link TheTVDB}
     */
    public static TheTVDB getInstance(String apiKey) {
        if (instance == null) {
            instance = new TheTVDB(apiKey);
        }
        return instance;
    }

    /**
     * Returns the API key which was set while getting the instance for the
     * first time.
     * 
     * @return the API key.
     */
    public String getApiKey() {
        return this.apiKey;
    }

    public List<Language> getAvailableLanguages() {
        return null;
    }

    public List<Mirror> getAvailableMirrors() {
        return null;
    }

}
